#include "ExplosionManager.h"
#include "ComponentManager.h"
#include "EntityExplosion.h"

CExplosionManager::CExplosionManager(void){}

CExplosionManager::~CExplosionManager(void)
{
	for(vector<CEntityExplosion*>::iterator i = m_vectorOfExplosionType.begin(); i!= m_vectorOfExplosionType.end(); i++)
	{
		delete (*i);
	}
}

void CExplosionManager::init(void)
{
	for(int i = 0; i<eNumberOfExplosion; i++)
	{
		CEntityExplosion* newExplosion = 0;//new CEntityExplosion(0, CVector2i(0, 0));
		m_vectorOfExplosionType.push_back(newExplosion);
	}
}

void CExplosionManager::createExplosionType(eExplosionType type, int indexAnim, int sound)
{
	if(type>=eNumberOfExplosion)
		return;

	CEntityExplosion* newExplosion = new CEntityExplosion(indexAnim, CVector2i(0,0), sound);
	m_vectorOfExplosionType[type] = newExplosion;
}

bool CExplosionManager::createExplosions(int numberOfEntities)
{
	for(int i=0; i<numberOfEntities; i++)
	{
		CEntityExplosion* newExplosion = CM.WORLD().createEntityExplosion(0, CVector2i(0, 0), 0);
		newExplosion->setActive(false);
		m_vectorExplosion.push_back(newExplosion);
	}

	return true;
}

bool CExplosionManager::activeExplosion(eExplosionType explosionType, const CVector2i& position)
{
	CEntityExplosion* type = m_vectorOfExplosionType[explosionType];

	for(vector<CEntityExplosion*>::iterator i = m_vectorExplosion.begin(); i!=m_vectorExplosion.end(); i++)
	{
		if(!(*i)->getActive())
		{
			//copy the type
			*(*i)=*type;

			//set position
			(*i)->setPosition(position);

			

			//set the projectile to active
			(*i)->setActive(true);

			
			return true;
		}
	}
	return false;
}
